<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__static/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }

        .layui-iconpicker-body.layui-iconpicker-body-page .hide {
            display: none;
        }

        .layui-iconpicker .layui-iconpicker-item {
            height: 36px;
        }

        .layui-iconpicker {
            margin-top: 10px;
        }

        .p_tree-box {
            border: 1px solid #e6e6e6;
            border-radius: 3px;
            margin-bottom: 15px;
            padding: 20px;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form layui-row">
        <input type="hidden" name="id" value="{$data.id|default='0'}">
        <div class="layui-col-lg2 layui-col-md3 layui-col-xs12">
            <div class="p_tree-box">
                <div class="layui-form-item">选择上级菜单</div>
                <div id="p_tree"></div>
            </div>
        </div>
        <div class="layui-col-lg10 layui-col-md9 layui-col-xs12">
            <div class="layui-form-item">
                <labe class="layui-form-label">上级菜单</labe>
                <div class="layui-input-inline">
                    <input type="hidden" name="pid" value="{$data.pid|default='0'}">
                    <input type="text" name="p_val" readonly="true" value="{$data.p_val|default='作为顶级菜单'}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">菜单名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="required" lay-reqtext="菜单名称不能为空" placeholder="请输入菜单名称" value="{$data.title|default=''}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-inline">
                    <input type="text" name="icon" placeholder="请输入图标类名" value="{$data.icon|default=''}" class="layui-input" lay-filter="iconPicker">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="text" id="iconPicker" value="{$data.icon|default=''}" style="display: none;">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">菜单url</label>
                <div class="layui-input-block">
                    <input type="text" name="href" placeholder="请输入菜单url" value="{$data.href|default=''}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <label class="layui-form-label">打开类型</label>
                <div class="layui-input-inline">
                    <select name="target">
                        <option value="_self" selected="">本页面</option>
                        <option value="_blank">新页面</option>
                        <option value="_parent">父框架</option>
                        <option value="_top">全窗口</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="status" lay-skin="switch" lay-text="显示|隐藏">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="number" name="sort" placeholder="请输入排序" value="{$data.sort|default=0}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
    <script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script>
        var id = {$data.id|default='0'};
        layui.use(['form', 'iconPickerFa', 'tree'], function() {
            var form = layui.form,
                layer = layui.layer,
                tree = layui.tree,
                iconPickerFa = layui.iconPickerFa,
                $ = layui.$;

            iconPickerFa.render({
                elem: '#iconPicker',
                url: "__static/lib/font-awesome-4.7.0/less/variables.less",
                search: true,
                limit: 16,
                click: function(d) {
                    var icon = 'fa ' + d.icon;
                    $('input[name=icon]').val(icon);
                },
                success: function(d) {
                    // console.log(d);
                }
            });
            
            $.get('/system/menu_edit/p_tree/json', function(d) {
                tree.render({
                    elem: '#p_tree',
                    data: d.data,
                    accordion: true,
                    onlyIconControl: true,
                    click: function(d) {
                        if (id == d.data.id)
                            return false;
                        $('input[name=pid]').val(d.data.id);
                        $('input[name=p_val]').val(d.data.title);
                    }
                });
            });

            //监听提交
            form.on('submit(saveBtn)', function(data) {
                var url = '/system/menu_save';
                layer.load(2);
                $.post(url, data.field, function(d) {
                    var index = layer.alert(d.msg, '', function() {
                        layer.close(index);
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                    layer.closeAll('loading');
                });

                return false;
            });

        });
    </script>
</body>

</html>